package com.cxs.plan.controller.power;

import com.cxs.plan.VO.UserVO;
import com.cxs.plan.domain.HttpResult;
import com.cxs.plan.domain.entity.User;
import com.cxs.plan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("user")
public class LoginController {

    @Autowired
    private UserService userService;


    @PostMapping("/login")
    public HttpResult LoginUser(@RequestBody User user) {
        String token = userService.loginUser(user.getUsername(), user.getPassword());
        Map<String, String> map = new HashMap<>();
        map.put("token", token);
        return HttpResult.success(map);
    }

    @GetMapping("/info")
    public HttpResult getUserInfo() {
        UserVO user = userService.getUserInfo();
        return HttpResult.success(user);
    }
}
